package values.item.building
{
import mx.utils.StringUtil;

import values.item.BuildingItemTemplateValue;
import values.item.ItemUpgradeValue;
import values.product.ProductTemplateValue;
import values.product.ProductTemplateValueList;

/**
 * FactoryBuildingItemTemplateValue
 * @author jliang
 *
 */
public class FactoryBuildingItemTemplateValue extends BuildingItemTemplateValue
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function FactoryBuildingItemTemplateValue()
	{
		super();
	}
	
	override public function get dynamicClassRef():Class
	{
		return FactoryBuildingItemValue;
	}
	
	protected var _productList:Vector.<ProductTemplateValue>;
	
	public function get productList():Vector.<ProductTemplateValue>
	{
		if (!_productList)
		{
			_productList = new Vector.<ProductTemplateValue>();
			for (var i:int = 1; i <= this.maxLevel; i++)
			{
				var uvo:ItemUpgradeValue = this.getUpgradeByLevel(i);
				var ps:Array = String(uvo.effect.product).split(",");
				for (var j:int = 0; j < ps.length; j++)
				{
					_productList.push(ProductTemplateValueList.getByKey(StringUtil.trim(ps[j])));
				}
			}
		}
		return _productList;
	}
	
	public function getProductByKey(key:String):ProductTemplateValue
	{
		for each (var p:ProductTemplateValue in productList)
		{
			if (p.key == key) return p;
		}
		return null;
	}
	
	public function getBonusPlusByLevel(lvl:int):Number
	{
		return this.getUpgradeByLevel(lvl).effect.plus;
	}
}
}